<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
%>
<!DOCTYPE HTML>
<html>
<head>
	<base href="<%=basePath%>">
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>消息接收角色列表（未使用）</title>
	<link rel="stylesheet" href="plugin/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="plugin/bootstrap-table/dist/bootstrap-table.css">
<style type="text/css">

ul{
    list-style-type: none;
}
 .breadcrumb{
          padding: 21px 25px;
       }  
 a {
    color: #2a3f54;
}        
</style>

</head>
<body>
    <div class="row base-margin" id="query">
        <ul class="breadcrumb">
				<li style="padding-left: 15px"><i class="icon-home home-icon"></i> <a href="javascript:void(0)">System Settings(系统设置)</a>
				</li>
				<li class="active">
				<a href="view/sys/userMessageRole_list.jsp">Role(消息角色列表)</a></li>
        </ul>
        <form class="form-inline" role="form" style="float: left; width: 100%" method="post" id="queryForm">
            <button type="button" style="margin-left:35px" id="queryBtn" onclick="add()" class="btn btn-primary">新建</button>
            <button type="button" style="margin-left:15px" id="queryBtn" onclick="updates()" class="btn btn-primary">修改</button>
            <button type="button" style="margin-left:15px" id="queryBtn" onclick="del()" class="btn btn-primary">删除</button>
           <div class="form-group" style="margin-left:15px">  
                <label for="bName">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;角色名称:</label> 
                <input type="text" class="form-control "  id="umRoleName" />
            </div>   
            <div class="form-group">
                <button type="button" id="queryBtn" onclick="doQuery1('demo-table',queryParams1());" class="btn btn-primary">搜索</button>
            </div> 
        </form>
    </div>
    <div class="container" style="width: 100%;margin-top:15px">
        <table id="demo-table">
        </table>
    </div>
</body>
	<!-- 加载需要的js -->
	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="plugin/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
	<script src="js/jquery-bootstrap-pagination.js"></script>
	<script src="plugin/bootstrap-table/dist/bootstrap-table.min.js"></script>
	<script src="plugin/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
	<!--时间  -->
	<script src="js/bootstrap-datetimepicker.js"></script>
	<script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
	<script src="js/common.js"></script>
	<script src="plugin/layer/layer.js"></script>
	<script type="text/javascript" charset="utf-8">
	$(function () {
		initPath("<%=basePath%>");
	    initTable('demo-table',queryParams,columns,"userMessageRole/getList");
	});
	//添加、修改
	function add(id,umRoleName){
		var title="添加消息接收角色";
			var str = "";
			 str+="<form class=\"form-horizontal\">"
				+"<div class=\"form-group\"><label  class=\"col-sm-3 control-label\">角色名称</label>"
				+"<div class='col-sm-3'>"
				+"<input class=\"form-control\" name='umRoleName' id='umRoleName' />"
				+"</div></div>"
				+"<div class=\"form-group\" style=\"padding-left: 10%\">"
				+" <button  onclick=\"save()\" class=\"btn btn-info\"style=\"width: 100px\">保存</button><button  onclick=\"cacel()\" style=\"width: 100px;margin-left:10px\" class=\"btn btn-info\">取消</button></div></form >";
				layer.open({
					  type: 1,
					  title: title,
					  skin: 'layui-layer-rim', //加上边框
					  area: ['440px', '340px'], //宽高
					  content: str
					});
		}
	function updates(){
		var title="修改消息接收角色";
		var rows=$('#demo-table').bootstrapTable("getSelections");
		if(rows.length==0){
			layer.alert("请选择一条记录修改");
			return;
		}
		if(rows.length>1){
			layer.alert("请仅选择一条记录做修改;");
			return;
		}
		var id = rows[0].id;
		var umRoleName = rows[0].umRoleName;
			var str = "";
			 str+="<form class=\"form-horizontal\" style='margin-left: 13px;'>"
				+"<div class=\"form-group\"><label  class=\"col-sm-3 control-label\">角色名称</label>"
				+"<div class='col-sm-3'>"
				+"<input class=\"form-control\" name='umRoleName' value='"+umRoleName+"' />"
				+"<input type='hidden' id=\"id\"  value='"+id+"'/></div></div>"
				+"<div class=\"form-group\" style=\"padding-left: 10%\">"
				+" <button  onclick=\"save('"+id+"')\" class=\"btn btn-info\"style=\"width: 100px\">保存</button><button  onclick=\"cacel()\" style=\"width: 100px;margin-left:10px\" class=\"btn btn-info\">取消</button></div></form >";
				layer.open({
					  type: 1,
					  title: title,
					  skin: 'layui-layer-rim', //加上边框
					  area: ['440px', '340px'], //宽高
					  content: str
					});
		}
	function save(id){
		var data;
		var umRoleName = $('input[name=umRoleName]').val();
		data={umRoleName:umRoleName};
		if(id!=undefined){
			data={id:id,umRoleName:umRoleName};
		}
		console.log(data);
		$.ajax({
			type:"post",
			url:"userMessageRole/addOrUpdate",
		    data: JSON.stringify(data),
             contentType:"application/json;charset=UTF-8", 
             dataType:"json",
			success:function(dat){
				 if(data.code==200){
					  layer.closeAll();
		          		$('#demo-table').bootstrapTable('refreshOptions',queryParams());
            	       }else{
            	    	    layer.msg(data.msg);
            	       }
			}
		});
	}
	//删除
	function del(){
		var rows=$('#demo-table').bootstrapTable("getSelections");
		if(rows.length==0){
			layer.alert("请选择一条记录修改");
			return;
		}
		var arr = new Array();
		for(var i in rows){
			arr.push(rows[i].id);
		}
		var ids=arr.join(',');
		var  flag =  confirm("你确定要删除吗?");	
		  if(flag){
				 $.ajax({
			            type: "get",
			            url: "userMessageRole/del",
			            data:{"ids":ids},
			            success: function(data){    
			           	  console.log(data)
			          	  if(data.code==200){	 
			          		$('#demo-table').bootstrapTable('refreshOptions',queryParams());
				        	 }else{
				        		  layer.msg(data.msg); 
				        	 }
			       }
			        }); 
		  }
	}
var  columns= [ 
	 { field : '',  title : '选择',checkbox:true },
	 { field : 'umRoleName',  title : '角色名称',  align : 'center', valign : 'middle' }];

function cacel(){
	layer.closeAll();
}
	function queryParams(params) {
		 console.log(params);  
	    var param = {
	    		umRoleName:$('#umRoleName').val(), 
	        pageNo : this.pageNumber,
	        pageSize : this.pageSize
	    }	
	    return param;
	} 
	function queryParams1(){
		 var param = {
				 umRoleName:$('#umRoleName').val(), 
		        pageNo : 1,
		        pageSize : this.pageSize
		    }	
		    return param;
	}
	</script>
</html>


